home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vmed.arc / VMGO.CCC < prev    next >
Encoding:
Text File  |  1985-12-03  |  3.5 KB  |  145 lines

  1. /* VMGO/CCC
  2.  *    virtual memory current-line control functions
  3.  *
  4.  *    Copyright 1983, 1984 by Jim Kyle - All Rights Reserved
  5.  *    Licensed for individual non-commercial use only.
  6.  *
  7.  *         created:    November 24, 1983 - Jim Kyle
  8.  *         changed:    February 11, 1984 - Jim Kyle
  9.  *    last changed:    March 3-9, 1984 - Jim Kyle
  10.  *
  11.  *
  12.     NOTE:
  13.     These routines are the only ones in the entire VM
  14.     system which are permitted to change the values of
  15.     the current-line counter Cur_ln and the data index
  16.     Dbndx. Other routines can and do change Flcb, Llcb,
  17.     and Lltf, especially when lines are moved from one
  18.     block to another, inserted, or deleted, but only
  19.     the VMGO module modifies the current line position.
  20.  */
  21.  
  22. /*
  23.  *    go_to() makes 'tgt' the current line
  24.  *    changed 2/29/84 to improve goto response time--jk
  25.  *    changed 3/7/84 to prevent going outside file--jk
  26.  */
  27. go_to(tgt)    int tgt;
  28. {    tgt = max(0, min(tgt,Lltf));    /* map into true range */
  29.     if (tgt <= (Cur_ln >>1))    /* closer to front... */
  30.         go_top();                /* sets Cur_ln to 0 or 1 */
  31.     else if ((tgt-Cur_ln)>(Lltf-tgt)) /* closer to end... */
  32.         go_eof();                /* sets Cur_ln to Lltf */
  33.     return(tgt > Cur_ln ? go_f(tgt) : go_p(tgt));
  34. }
  35.  
  36. /*
  37.  *    go_nxl() makes next line the current one
  38.  */
  39. go_nxl()
  40. {    return(go_f(Cur_ln + 1));    }
  41.                                  
  42. /*
  43.  *    go_pvl() makes prev line the current one
  44.  */
  45. go_pvl()
  46. {    return(go_p(Cur_ln - 1));    }
  47.  
  48. /*
  49.  *    go_f() moves toward EOF until 'tgt' is found
  50.  */
  51. go_f(tgt)    unsigned int tgt;    /* changed 3/7/84 - jk */
  52. {    tgt = min(tgt, Lltf);        /* stay inside the file */
  53.     while (tgt > Llcb)    {
  54.         if (*Nxptr)
  55.             vm_abt(go_nxb(), "go_f");
  56.         else
  57.             tgt = Llcb;        /* catch empty file condition */
  58.     }
  59.     while (tgt > Cur_ln++)
  60.         Dbndx += getwd(clad());
  61.     --Cur_ln;        /* take out the overshoot!! */
  62.     return(OK);
  63. }
  64.  
  65. /*
  66.  *    go_p() moves toward HOF until 'tgt' is found
  67.  */
  68. go_p(tgt)    int tgt;
  69. {    if (tgt < 2) return(go_top());
  70.     while (tgt < Flcb)    {
  71.         if (Curr)            /* 3-7-84 */
  72.             vm_abt(go_pvb(), "go_p");
  73.         else
  74.             tgt = Flcb;        /* 3-3-84 -- stop at top!!! */
  75.     }
  76.     Cur_ln = Flcb;
  77.     Dbndx = 0;
  78.     return(go_f(tgt));
  79. }
  80.  
  81. /*
  82.  *    go_top() goes to front of file without search
  83.  */
  84. go_top()
  85. {    vm_abt(vm_get(0), "go_top");
  86.     Dbndx = 0;
  87.     Cur_ln = Flcb = 1;
  88.     Llcb = *Lcptr;
  89.     return(Llcb ? OK : go_nxb());    /* 3-3-84 */
  90. }
  91.  
  92. /*
  93.  *    go_eob() goes to the last line of the current
  94.  *    block.
  95.  */
  96. go_eob()
  97. {    unsigned int tmp;
  98.     tmp = Flcb;                    /* start at top */
  99.     Dbndx = 0;
  100.     while (tmp++ < Llcb)        /* step thru block */
  101.         Dbndx += getwd(clad());
  102.     if ((Cur_ln = Llcb) < Flcb) go_pvb();    /* empty! */
  103. }
  104.  
  105. /*
  106.  *    go_eof() goes to end of file without search
  107.  */
  108. go_eof()
  109. {    vm_abt(vm_get(0), "go_eof 1");
  110.     vm_abt(vm_get(*Pvptr), "go_eof 2");
  111.     Flcb = (Llcb =Lltf) + 1 - *Lcptr;    /* 3-9-84 */
  112.     return(go_eob());                    /* 3-9-84 */
  113. }
  114.  
  115. /*
  116.  *    go_pvb() moves to last line of prev block.
  117.  *    If on first block, returns OK.
  118.  */
  119. go_pvb()
  120. {    if (Curr)    {
  121.         Llcb -= *Lcptr;            /* set for new block */
  122.         vm_abt(vm_get(*Pvptr), "go_pvb");
  123.         Flcb = Llcb - *Lcptr + 1;
  124.         go_eob();
  125.     }
  126.     /* else at front: */
  127.     return(OK);                    /* 3-9-84 */
  128. }
  129.  
  130. /*
  131.  *    go_nxb() moves to first line of next block.
  132.  *    If on last block, returns OK.
  133.  */
  134. go_nxb()
  135. {    if (*Nxptr)    {
  136.         vm_abt(vm_get(*Nxptr), "go_nxb");
  137.         Cur_ln = Flcb = Llcb + 1;    /* Llcb is of OLD */
  138.         Llcb += *Lcptr;
  139.         Dbndx = 0;
  140.     }
  141.     /* else at end: */
  142.     return(OK);                        /* 3-9-84 */
  143. }
  144.  
  145.